#ifndef _STRETCH_KERNEL_
#define _STRETCH_KERNEL_

float KernelCubic(float x)
{
	if (x < 0.0f) x = -x;
	float x2 = x * x;
	if (x < 1) return 1.0f - 2 * x2 + x2 * x;
	if (x < 2) return 4.0f - 8 * x + 5.0f * x2 - x2 * x;
	return 0;
}

float KernelBSpline(float x)
{
	if (x > 2.0f) return 0;
	float a, b, c, d;
	float xm1 = x - 1.0f;
	float xp1 = x + 1.0f;
	float xp2 = x + 2.0f;
	if ((xp2) <= 0.0f)
		a = 0.0f;
	else
		a = xp2 * xp2 * xp2;
	if ((xp1) <= 0.0f)
		b = 0.0f;
	else
		b = xp1 * xp1 * xp1;
	if (x <= 0)
		c = 0.0f;
	else
		c = x * x * x;  
	if ((xm1) <= 0.0f)
		d = 0.0f;
	else
		d = xm1 * xm1 * xm1;
	return (1.0f / 6.0f * (a - (4.0f * b) + (6.0f * c) - (4.0f * d)));
}

float KernelSinc(float x) 
{
	const float a = -1.0f;
	if (x < 0.0f) x = -x;
	if (x == 0.0f)
		return 1.0f;
	float x2 = x * x;
	float x3 = x2 * x;
	if (x <= 1)
		return (a + 2) * x3 - (a + 3) * x2 + 1;
	else if (x <= 2) 
		return a * x3 - (5 * a) * x2 + (8 * a) * x - (4 * a);
	else
		return 0;
} 

#endif